<?php
class Album
{
    private $id;
    private $name;
    private $songs;
    private $info;
    private $cover;

    /**
     * Constructor
     */
    public function Album( ){
        $this->songs=array();
    }

    /**
     * Sets the name of the album
     * @param String $name The name of the album
     */
    public function setName($name){
        $this->name=$name; 
    }
    
    /**
     * Sets the id of the album
     * @param int $id The id 
     */
    public function setID($id){
        if(is_numeric($id)){
            $this->id=$id;
        }
    }
    /**
     * Returns the id
     * @return int id 
     */
    public function id(){
        return $this->id;
    }
    
    /**
     * Adds a track to the array of tracks
     * @param Track $track The track
     */
    public function addTrack($track){
        array_push($this->songs,$track);
    }
          
    /**
     * Sets the info of the album
     * @param String $info The info
     */
    public function setInfo($info){
        $this->info=$info; 
    }

    /**
     * Sets the cover of the album
     * @param String $cover The cover link
     */
    public function setCover($cover){
        $this->cover=$cover; 
    }

    /**
     * Returns the name of the album
     * @return String name The name of the album 
     */
    public function name(){
        return $this->name;
    }
    
    /**
     * Returns all the tracks that this album has
     * @return Array track The tracks 
     */
    public function songs(){
        return $this->songs;
    }

    /**
     * Returns the information about this album
     * @return String info The information
     */
    public function info(){
        return $this->info;
    }
    /**
     * Returns the cover link
     * @return String link The cover link 
     */
    public function cover(){
        return $this->cover;
    }
    /**DEPRECATED
     * We don't keep track anymore of the listen count of an album
     * @return type 
     */
    public function listened(){
        return $this->listened;
    }

    /**DEPRECATED
     * We don't use toString methods, only toJSON
     * @return string 
     */
    public function toString(){
        $out='';
        $out.='name['.$this->name.']'.',';
        $out.='songs['.$this->songs.',';
        $out.='info['.$this->info.']'.',';
        $out.='cover['.$this->cover.']'.',';
        return $out;
    }
    /**DEPRECATED
     * 
     * @param Album $that
     * @return type 
     */
    public function equals($that){
        if($that instanceof Album){
            if(strcmp($this->name,$that->name())==0){
                return true;
            }
        }
        return false;
    }
    /**
     * Returns a toJSON description of this object
     * @return Array JSON The JSON format of this object 
     */
    public function toJSON(){
        $out=array();
        $out['name']=$this->name;
        $out['tracks']=array();
        if($this->songs!=null){
            if($this->songs[0] instanceof Track){
                foreach($this->songs as $track){
                    array_push($out['tracks'], $track->toJSON());
                }
            }
            else{
                foreach($this->songs as $track){
                    array_push($out['tracks'], $track);
                }
            }
        }
        $out['id']=$this->id;
        $out['info']=$this->info;
        $out['cover']=$this->cover;
        return $out;
    }
}
?>
